﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using HRM.DTO;

namespace HRM.DL
{
    public class DL_BOPHAN
    {
        #region "Cp"
        #region "Variable" //-----------------------------
        string _error = "";
        Thuvien tv;
        DataSet _ds;
        DataTable _dt;
        #endregion

        #region "Properties" //------------------------------------
        public DataTable Dt
        {
            get { return _dt; }
            set { _dt = value; }
        }
        public string Error
        {
            get { return _error; }
            set { _error = value; }
        }
        public DataSet Ds
        {
            get { return _ds; }
            set { _ds = value; }
        }
        #endregion
        public DL_BOPHAN()
        {
            tv = new Thuvien();
            _ds = new DataSet();
            _dt = new DataTable();
        }
        public bool GetDataset(string sqlselect)
        {
            if (tv.Conn.State == ConnectionState.Closed)
                if (!tv.Connect())
                {
                    _error = tv.Error;
                    return false;
                }
            int result = -1;
            try
            {
                SqlDataAdapter adapter = new SqlDataAdapter(sqlselect, tv.Conn);
                result = adapter.Fill(_ds);
            }
            catch (Exception ex)
            {
                _error = " Lỗi không tải được dữ liệu từ CSDL. " + result.ToString() + "\n" + ex.ToString();
            }
            if (!tv.Disconect())
            {
                _error = tv.Error;
                return false;
            }
            if (result < 0)
                return false;
            return true;
        }
        #endregion
    }
}
